package com.huawei;

/**
 * Created by Z-hong on 2024/7/23.
 */

import java.util.Scanner;

public class HJ65 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str_1 = scanner.nextLine();
        String str_2 = scanner.nextLine();
        String flag = "";
        flag = str_1.length() > str_2.length() ? str_2 : str_1;
        String result = "";
        int index = Integer.MAX_VALUE;
        int max = 0;

        char[] arr_1 = str_1.toCharArray();
        char[] arr_2 = str_2.toCharArray();
        for (int i = 0; i < arr_1.length; i++) {
            for (int j = 0; j < arr_2.length; j++) {
                if (arr_1[i] != arr_2[j]) continue;
                int z = i, k = j;
                String res = "";
                while (z < arr_1.length && k < arr_2.length && arr_1[z] == arr_2[k]) {
                    res += arr_1[z];
                    z++;
                    k++;
                }
                if (res.length() > max) {
                    max = res.length();
                    index = flag.indexOf(res);
                    result = res;
                } else if (res.length() == max) {
                    if (flag.indexOf(res) < index) {
                        index = flag.indexOf(res);
                        result = res;
                    }
                }
            }
        }

        System.out.println(result);
    }
}
